Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
Issues with winning counts | Rock paper scissor game

I've been having this issue for several hours and I thought it's finally time to ask for some help. The issue is that my winning counts won't increment according to the winner declared on every of the 5 rounds. I'm sorry if my code is messy or over complicated.

// The initial variable declarations including the user's pre-picked input/
let computerChoice;
let userChoice = 'paper';

// The function picks a random number that will change the computerChoice variable's value
function computerPlay() {
  computerChoice = Math.floor(Math.random() * 3);
  switch (computerChoice) {
    case 0:
      computerChoice = 'rock';
      break;
    case 1:
      computerChoice = 'paper';
      break;
    case 2:
      computerChoice = 'scissors';
      break;
  }
}

// The function will pick a round winner
function userPlay(userChoice) {
  return userChoice.toLowerCase();
}

function playRound() {
  computerPlay();
  if ((computerChoice === 'rock' && userChoice === 'scissors') || (computerChoice === 'paper' && userChoice === 'rock') || (computerChoice === 'scissors' && userChoice === 'paper')) {
    return `You lost! Computer chose ${computerChoice}.`
  } else if (computerChoice === userChoice) {
    return `It's a tie! Computer chose ${computerChoice}.`
  } else {
    return `You won! Computer chose ${computerChoice}.`
  }
}
// The function will pick a winner of 5 rounds *not working*
function game() {
  let userWinnerCount = 0;
  let computerWinnerCount = 0;
  let ties = 0;
  for (let i = 0; i < 5; i++) {
    console.log(playRound());
    if (playRound() === `You won! Computer chose ${computerChoice}.`) {
      userWinnerCount += 1
    } else if (playRound() === `You lost! Computer chose ${computerChoice}.`) {
      computerWinnerCount += 1
    } else {
      ties += 1
    }
  }
  console.log(`${userWinnerCount} - times the user won / ${computerWinnerCount} - times the computer won / ${ties} - Ties`);
}
game()

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda